<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="./css/index.css"/>
    <script src="js/jquery-3.2.1.min.js"></script>
    <!--退出登录-->
    <script src="js/loginOut.js"></script>
    <title>密码找回</title>
</head>
<body>
<header>
    <div class="lf">
        <a class="home" href="index.html">系统首页</a>
        <!-- <a href="bbs.html">论坛</a> -->
        <a href="upload.html">上传资料</a>
    </div>
    <div id="search">
        <input type="text" name="name"
               placeholder="请输入要搜索的资源" autocomplete="off"/><a class="search btn">搜索</a>
    </div>

    <div class="rf">
<!--        <a href="login.html">登录/注册</a>-->
        <a class="info" href="personal.html">个人中心</a>
        <a class="cols" href="shoucang.html">收藏</a>
        <a class="exit">退出登录</a>
    </div>
</header>
<article>
    <!-- 网站主体 -->
    <div id="main">
        <section class="ct">
            <div class="upload">
                <h1>修改密码</h1>
                <form id="passwordForm" action="" method="post">
                    <p>
                        <label>旧密码：</label>
                        <input class="upt" id="oldPassword-input" type="password" name="oldPassword" value=""
                               placeholder="请输入原密码"/>
                        <em></em>
                    </p>
                    <p>
                        <label>新密码：</label>
                        <input class="upt" id="newPassword-input" type="password" name="newPassword" value=""
                               placeholder="请输入新密码"/>
                        <em></em>
                        <span class="source-tag-msg">密码长度为6~20</span>
                    </p>
                    <p>
                        <label>确认密码：</label>
                        <input class="upt" id="confirmPassword-input" type="password" name="confirmPassword" value=""
                               placeholder="请再次输入新密码"/>
                        <em></em>
                        <span class="source-tag-msg">两次输入的密码必须保持一致</span>
                    </p>

                    <p><label class="btn"><a class="btn" id="confirmButton">确认修改</a></label></p>
                </form>
            </div>
        </section>
    </div>
</article>
<footer>
    <p class="decro">本站所有资源信息均由网友上传,本站只是为了推广资源让更多读者下载,使用。如涉侵权，请联系管理员</p>
    <p class="cr">Copyright © 2021-2025 <span class="site">爱下载资源分享平台</span> All Rights Reserved.</p>
    <p class="num">沪ICP备14048333号</p>
</footer>


</body>
<script>
    //修改密码
    $(function () {
        $("#confirmButton").on("click", function() {
        	console.log($(this));
        	var oldPassword = $("#oldPassword-input").val();
        	var newPassword = $("#newPassword-input").val();
        	var confirmPassword = $("#confirmPassword-input").val();

        	// 验证密码长度和确认密码是否匹配
        	if (newPassword.length >= 6 && newPassword.length <= 20 && newPassword === confirmPassword) {
        		// 发送数据给后端
        		$.ajax({
        			type: "post",
        			url: "UpdateServlet/updatePassword",
        			data: {oldPassword: oldPassword, newPassword: newPassword},
        			success: function(data) {
        				if (data.code==602){
        					alert("密码修改成功请重新登录！");
                            location.href = "login.html";
        				}else {
        					alert(data.msg);
        				}
        			}
        		});
        	} else {
        		// 如果密码不符合要求或确认密码不匹配，显示相应的错误信息
        		if (!/^[A-Za-z0-9]{6,20}$/.test(newPassword)) {
        			// 密码长度错误提示
        			alert("密码长度需在6到20位之间");
        		}
        		if (newPassword !== confirmPassword) {
        			// 确认密码不匹配提示
        			alert("新密码与确认密码密码不一致");
        		}
        	}
        });
    });
</script>
</html>